<template>
	<view style="padding: 30rpx;">
		<view :style="{height: statusBarHeight+'px'}"></view>
		<view class="u-flex">
			<view @click="topleftClick">
				<u-icon name="arrow-left"size="50"color="#000"></u-icon>
			</view>
			<u-search placeholder="高质量书籍" shape="squre" style="margin-left: 20rpx;" @custom="custom"
			v-model="input"></u-search>
		</view>
		<view v-for="(item,index) in bookDataName" :key="index" style="margin: 30rpx 0;">
			<book-item-name :item="item" @itemClick="itemClick"></book-item-name>
		</view>
		<view v-if="bookDataName.length == 0" style="text-align: center;margin-top: 100rpx;">
			<text style="color: #999999;font-size: 36rpx;">暂无此书数据</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bookDataName:[],
				input:"",
				statusBarHeight:0
			}
		},
		mounted() {
			let that = this
			//获取手机系统信息
			const info = uni.getSystemInfoSync()
			//设置状态栏高度
			that.statusBarHeight = info.statusBarHeight
			
		},
		methods: {
			saveHistroy(e){
				let searchFor = uni.getStorageSync("searchFor") || []
				searchFor.unshift(e)//向前追加对象
				searchFor = searchFor.slice(0,8)
				uni.setStorageSync("searchFor",searchFor)
			},
			topleftClick(){
				uni.navigateBack({
					
				})
			},
			//
			async getBookDataName(e){
				let name = ""
				if(e != ""){
					name = e
				}
				const res=await this.$myRequst({
					url:"/bookData/gets/"+name
				})
				this.bookDataName = res.data.data
				console.log(res.data.data)
			},
			custom(e){
				this.getBookDataName(e)
			},
			itemClick(e){
				uni.navigateTo({
					url:"../bookItem/bookItem?id="+e
				})
			},
			async getBookListType(e){
				const res=await this.$myRequst({
					url:"/bookData/getsType/"+e
				})
				this.bookDataName = res.data.data
				console.log(res.data)
			}
		},
		onLoad(opstion) {
			if(opstion.item){
				this.input = opstion.item
				this.saveHistroy(opstion.item)
				this.getBookDataName(opstion.item)
			}else if(opstion.type){
				this.getBookListType(opstion.type)
			}

		}
	}
</script>

<style>

</style>
